#include <iostream>
#include <stack>
#include <string>
using namespace std;
class Solution {
public:
    string removeDuplicates(string s) {
        stack<char> aa;
        for (char word : s) {
            if (!aa.empty() && aa.top() == word) {
                aa.pop();
            }
            else {
                aa.push(word);
            }
        }
        string result;
        while (!aa.empty()) {
            result = aa.top() + result;
            aa.pop();
        }

        return result;
    }
};
class Solution {
public:
    string removeDuplicates(string s) {
        string stack;
        for (char num : s) {
            if (!stack.empty() && stack.back() == num) {
                stack.pop_back();
            }
            else {
                stack.push_back(num);
            }
        }
        return stack;
    }
};